package com.example.zhangxuemin.fragmenttest130zxm.model;

import com.example.zhangxuemin.fragmenttest130zxm.iface.RegListener;
import com.example.zhangxuemin.fragmenttest130zxm.service.RegService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * Created by zhangxuemin on 2017/5/31.
 */

public class RegModel {
    private Retrofit retrofit;
    private static final String BASE_URL = "http://amicool.neusoft.edu.cn/";//主机地址

    public RegModel(){
        retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)               //主机地址
                .addConverterFactory(ScalarsConverterFactory.create()) //解析方式
                .build();
    }


    public void reg(String User, String PassWord, String Tel,String Repassword, final RegListener listener) {
        RegService regService =retrofit.create(RegService.class);
        Call<String> call=regService.reg(User,PassWord,Tel,Repassword);
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                listener.onResponse(response.body());
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
}
